﻿using System;
using System.Windows.Forms;

namespace SwimmingCompetitions
{
    public partial class Expander : UserControl
    {
        public Expander()
        {
            ExpandedWidth = 250;
            InitializeComponent();
            Width = _buttonExpand.Width;
        }

        public int ExpandedWidth { get; set; }

        public bool Expanded 
        {
            get { return _buttonExpand.RightToLeft == RightToLeft.Yes; }
        }

        public void Expand()
        {
            if (Expanded) return;
            Hide();
            _buttonExpand.RightToLeft = RightToLeft.Yes;
            Width = ExpandedWidth;
            Parent.Width += ExpandedWidth - _buttonExpand.Width;
            Show();
            _resultsView.Show();
        }

        public void Close()
        {
            if (!Expanded) return;
            _resultsView.Hide();
            _buttonExpand.RightToLeft = RightToLeft.No;
            Width = _buttonExpand.Width;
            Parent.Width -= ExpandedWidth - _buttonExpand.Width;
        }

        public void UpdateResults(CompetitionModel model)
        {
            _resultsView.Initialize(model);
        }

        private void buttonExpandClick(object sender, EventArgs e)
        {
            if (_buttonExpand.RightToLeft == RightToLeft.Yes)
            {
                Close();
            }
            else
            {
                Expand();
            }
        }
    }
}
